package cn.neusoft.edu.his.demo.controller;

import io.swagger.annotations.Api;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.neusoft.edu.his.demo.common.Result;
import cn.neusoft.edu.his.demo.mapper.DoctorMapper;
import cn.neusoft.edu.his.demo.po.Doctor;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

@CrossOrigin
@Api("DoctorControlloer相关的api")
@RestController
public class DoctorController {
	@Autowired
	private DoctorMapper doctorMapper;
	
	@RequestMapping("/getDoctors")
	public Result getDoctors(){
		List<Doctor> list=doctorMapper.selectList(null);
		return Result.ok(list);
	}
	@RequestMapping("/addDoctors")
	public void addDoctors(Doctor doctor){
		SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");//设置日期格式
		String date = df.format(new Date());
		doctor.setDocId(date);
		System.out.println("医生信息"+doctor);
		int insert = doctorMapper.insert(doctor);

	}
	@RequestMapping("/deleteDoctors")
	public void deletedoctor(Doctor doctor){
		doctorMapper.deleteById(doctor.getDocId());
	}

	@RequestMapping("/updateDoctors")
	public void updateDoctors(Doctor doctor){
		doctorMapper.updateById(doctor);
	}

	@RequestMapping("/getDoctorsId")
	public Result getDoctors(Doctor doctor){
		List<Doctor> Doctor = doctorMapper.getDoctor(doctor);
		return Result.ok(Doctor);
	}
	//根据传入的名字和电话号获取医生的Id
	@RequestMapping("/getDoctorsByNameAndTelephone")
	public Result getDoctorsByNameAndTelephone(Doctor doctor){
		Doctor Doctor = doctorMapper.getDoctor1(doctor);
		return Result.ok(Doctor);
	}
	@RequestMapping("/getDoctorsByDp1")
	public Result getDoctorsById(Doctor doctor){
		QueryWrapper<Doctor> Wrapper = new QueryWrapper<>();
		Wrapper.eq("depart_id1",doctor.getDepartId1());
		List<Doctor> doctors = doctorMapper.selectList(Wrapper);
		return  Result.ok(doctors);
	}
	@GetMapping("/getDoctorsByName")
	public Result getDoctorsByName(Doctor doctor){
		QueryWrapper<Doctor> Wrapper = new QueryWrapper<>();
		Wrapper.eq("doc_id",doctor.getDocId());
		List<Doctor> doctors = doctorMapper.selectList(Wrapper);
		return  Result.ok(doctors);
	}
	@GetMapping("/getDoctorId/{doctorId}")
	public Result getDoctorsByName(@PathVariable String doctorId){
		Doctor doctors = doctorMapper.selectById(doctorId);
		return  Result.ok(doctors);
	}
	//是否推荐
	@GetMapping("/updateRecommend")
	public int updateRecommend(Doctor doctor){
		int i = doctorMapper.updateRecommend(doctor);
		return i;
	}
	//是否推荐展示查询
	@GetMapping("/getDoctorsRecommend")
	public Result getDoctorsRecommend(){
		QueryWrapper<Doctor> Wrapper = new QueryWrapper<>();
		Wrapper.eq("recommend","1");
		List<Doctor> doctors = doctorMapper.selectList(Wrapper);
		return  Result.ok(doctors);
	}
}
